package com.linhz.demo07.Sychronized;

import com.sun.org.apache.xpath.internal.objects.XObject;

public class RunnableImpl implements Runnable{
    private int ticket = 100;

    // 创建一个锁对象
    Object obj = new Object();

    @Override
    public void run() {
        while(true){
            synchronized (obj) {
                if (ticket>0){
                    try{
                        Thread.sleep(10);
                    }catch (InterruptedException e){
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName()+"-->正在卖"+ticket+"张票");
                    ticket--;
                }
            }

        }
    }
}
